#include "server.h"
#include <iostream>
#include <csignal>

GameServer* server = nullptr;

void signalHandler(int signum) {
    std::cout << "Interrupt signal (" << signum << ") received.\n";
    if (server) {
        server->stop();
    }
    exit(signum);
}

int main() {
    // Register signal handler
    signal(SIGINT, signalHandler);
    signal(SIGTERM, signalHandler);
    
    const int GAME_WIDTH = 58;
    const int GAME_HEIGHT = 26;
    const int PORT = 7070;
    
    try {
        server = new GameServer(GAME_WIDTH, GAME_HEIGHT, PORT);
        std::cout << "Starting game server on port " << PORT << std::endl;
        server->start();
    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }
    
    delete server;
    return 0;
}